<!-- 自定义标准图表 设置百分百宽度 通过平台组件来适配尺寸 可以替换数据以及设置高级属性自定义扩展 详细查看组件示例.txt
  注:如需设置图片存放文件夹名称需应与当前文件名一致(1并在aircim.webpack.build.component.config.js配置需要打包的文件 2.npm run lib_c 执行打包命令  最后的组件会打包在components/grids中)-->
<template>
  <div class="scale-box" :id="dynamicIdName()">
    <div
        class="service-efficiency-box animate__animated"
        :class="dynamicClassName"
        style="width: 460px;height: 364px;"
        :id="dynamicChildName()"
    >
      <h1 class="h1_title">
        <span>差评分析</span>
      </h1>
      <TableScroll :container-height="257" :speed="10">
        <ul class="list">
          <li class="list-item" v-for="(item,index) in list" :key="index">
            <div class="item-index">{{ num2index(index+1) }}</div>
            <div class="item-content">
              <div class="item-content-container" style="gap:38px;margin-bottom: 9px">
                <p>差评办件：<em>{{item.num}}</em> <span>件</span></p>
                <p>差评占比：<em>{{ item.per }}</em> <span>%</span></p>
              </div>
              <div class="item-content-container">
                <p style="width: 70px;">差评原因：</p>
                <p class="omit2" style="flex: 1" :title="item.reason">{{ item.reason }}</p>
              </div>
            </div>
          </li>
        </ul>
      </TableScroll>
    </div>
  </div>
</template>
<script>
//引入封装方法
import encapsulation from "../../utils/aircimGird";
import TableScroll from "./TableScroll.vue"
export default {
  //混入封装方法
  mixins: [encapsulation],
  components: {
    TableScroll
  },
  data: function() {
    return {
      resizeObserver: null,
      //动态Id
      timestamp: null,
      list:[
        {
          num:12,
          per:'12.43',
          reason:'这里差评原因字段内容字段内容字段内容字段内容字段内容这里差评原因字段内容字段内容字段内容字段内容字段内容字段内容'
        },
        {
          num:132,
          per:'1.43',
          reason:'这里差评原因字段内容字段内容字段内容字段内容字段内容这里差评原因字段内容字段内容字段内容字段内容字段内容字段内容'
        },
        {
          num:122,
          per:'14.43',
          reason:'这里差评原因字段内容字段内容字段内容字段内容字段内容这里差评原因字段内容字段内'
        }
      ]
    };
  },
  mounted() {
    this.timestamp = new Date().getTime();
    this.$nextTick(() => {
      // 监听盒子变化
      this.listenChangeFn();
    });
  },
  methods: {
    num2index(v){
      console.log(v)
      if(v<10){
        return '0'+v;
      }
      return v;
    },
    //监听外部盒子的大小 然后对数据井行缩放
    scaleFn() {
      const parentBox = document.getElementById(`dynamic-${this.timestamp}`);
      const childBox = document.getElementById(
          `dynamicChild-${this.timestamp}`
      );
      const parentWidth = parentBox.offsetWidth;
      const parentHeight = parentBox.offsetHeight;
      const childWidth = childBox.offsetWidth;
      const childHeight = childBox.offsetHeight;
      let scaleX, scaleY;
      if (parentWidth < childWidth || parentHeight < childHeight) {
        const scaleBasedOnWidth = parentWidth / childWidth;
        const scaleBasedOnHeight = parentHeight / childHeight;
        scaleX = scaleBasedOnWidth;
        scaleY = scaleBasedOnHeight;
      } else {
        scaleX = parentWidth / childWidth;
        scaleY = parentHeight / childHeight;
      }
      childBox.style.transform = `scale(${scaleX}, ${scaleY})`;
    },
    // 监听盒子变化
    listenChangeFn() {
      let that = this;
      const element = document.getElementById(`dynamic-${this.timestamp}`);
      // console.log(element, "element");
      if (element) {
        new ResizeObserver(() => {
          // 处理元素大小变化的逻辑
          that.scaleFn();
        }).observe(element);
      }
    },
    // 绑定动画样式 animate__flash
    bindAnimationFn(animateName) {
      if (animateName != null) {
        this.dynamicClassName = animateName;
      }
    },
    //定义唯一ID名
    dynamicIdName() {
      return `dynamic-${this.timestamp}`;
    },
    //定义唯一ID名
    dynamicChildName() {
      return `dynamicChild-${this.timestamp}`;
    },
  },
  // 销毁监听
  beforeDestroy() {
    // 组件销毁前停止监听
    if (this.resizeObserver) {
      this.resizeObserver.disconnect();
    }
    if (this.requestTime != null) {
      clearInterval(this.requestTime);
    }
  },
};
</script>
<style lang="scss" scoped>
@import "../../static/assets/common.scss";
</style>
<style lang="scss" scoped>
.scale-box {
  width: 100%;
  height: 100%;
}

.service-efficiency-box {
  position: absolute;
  padding: 0 20px;
  box-sizing: border-box;
  overflow: hidden;
  transform-origin: left top;
  background-image: url(../../../thumbnail/backImg/new-border-mini-green.png);
  background-size: 100% 100%;
  background-repeat: no-repeat;
  color: #fff;
}
.list{
  margin-top: 26px;
  display: flex;
  flex-direction: column;
  gap: 23px;
  &-item{
    display: flex;
    gap: 15px;
    width: 420px;
    height: 117px;
    padding: 21px 14px 0 17px;
    background: url(../../static/assets/AssessAnalyse/bg.png) no-repeat center center;
    background-size: cover;
  }
  .item-index{
    padding-top: 4px;
    display: flex;
    justify-content: center;
    width: 43px;
    height: 41.701px;
    background: url(../../static/assets/AssessAnalyse/no_icon.png) no-repeat center center;
    background-size: cover;
  }
  .item-content{
    width: 331px;
    &-container{
      display: flex;
      font-weight: 400;
      font-family: "Source Han Sans CN";
      span{
        color: #96BEE0;
        font-size: 14px;
      }
      em{
        color: #FFBD3C;
        text-align: center;
        font-family: D-DIN;
        font-size: 20px;
        font-weight: 700;
      }
      p{
        color: #FFF;
        font-size: 14px;
      }
    }
  }
}
.omit2 {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}
</style>
